package com.hhh;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisPoolUtils {
	private static JedisPool pool=null;
	static{
		InputStream inputStream=JedisPoolUtils.class.getClassLoader().getResourceAsStream("redis.properties");
		Properties properties=new Properties();
		try {
			properties.load(inputStream);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		JedisPoolConfig poolConfig=new JedisPoolConfig();
		poolConfig.setMaxIdle(Integer.parseInt(properties.getProperty("redis.MaxIdle").toString()));//最大闲置个数
		poolConfig.setMinIdle(Integer.parseInt(properties.getProperty("redis.MinIdle").toString()));//最小闲置个数
		poolConfig.setMaxTotal(Integer.parseInt(properties.getProperty("redis.MaxTotal").toString()));//最大连接数
		pool=new JedisPool(poolConfig,properties.getProperty("redis.url").toString(),Integer.parseInt(properties.getProperty("redis.port").toString()));
	}
	public static Jedis getJedis(){
		
		return pool.getResource();
	}
}
